<template>
  <div>
    <h2>用户借款</h2>
    <table border="1">
      <tr>
        <td>借款名称</td>
        <td>
          <input type="text" v-model="info.jname">
        </td>
      </tr>
      <tr>
        <td>借款最高金额</td>
        <td>
          <input type="text" v-model="info.maxprice">
        </td>
      </tr>
      <tr>
        <td>借款最高年限</td>
        <td>
          <input type="text" v-model="info.maxyear">
        </td>
      </tr>
      <tr>
        <td>利息率</td>
        <td>
          <Select v-model="info.lixi">
            <option value="1%">1%</option>
            <option value="2%">2%</option>
            <option value="3%">3%</option>
            <option value="4%">4%</option>
          </Select>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <input type="button" value="借款" @click="jiekuan">
        </td>

      </tr>

    </table>

  </div>
</template>

<script setup lang="ts">
import { ref ,onMounted } from 'vue';
import axios from 'axios'
import { useRouter, useRoute} from 'vue-router';
const router = useRouter()
const route = useRoute();
const info=ref({
  jname:"",
  maxprice:"",
  maxyear:"",
  lixi:"",

})

//钩子函数
onMounted(()=>{
  fan(0);
})

//反填
const fan=(jid:any)=>{
  axios({
    url:"http://localhost:18964/api/CF/fantian",
    method:"get",
    params:{
      jid:route.params.jid
    }
  }).then((res)=>{
    info.value=res.data

  })

}

//借款
const jiekuan=(jid:any)=>{
  if(confirm("确定要借款吗？"))
  {
  axios({
    url:"http://localhost:18964/api/CF/update",
    method:"post",
    data:info.value,
    params:{
      jid:route.params.jid
    }
  }).then ((res)=>{
    if(res.data>0){
      alert("借款成功");
      router.push("/UserView")
    }else{
      alert("借款失败")
    }
  })
}
}


</script>


<style scoped>

</style>